import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [{
  path: '/login',
  component: () =>
    import('@/views/login/index'),
  hidden: true
},

{
  path: '/404',
  component: () =>
    import('@/views/404'),
  hidden: true
},

{
  path: '/',
  component: Layout,
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    name: '首页',
    component: () =>
      import('@/views/dashboard/index'),
    meta: { title: '欢迎', icon: 'dashboard' }
  }]
},

{
  path: '/order',
  component: Layout,
  redirect: '/order/orderlist',
  name: 'order',
  meta: { title: '订单管理', icon: 'el-icon-s-order' },
  children: [{
    path: '/order/orderlist',
    name: 'Table',
    component: () =>
      import('@/views/orderlist/index'),
    meta: { title: '订单列表', icon: 'el-icon-s-order' }
  },
  {
    path: '/order/orderdetails/:orderId',
    name: 'orderdetails',
    component: () =>
      import('@/views/orderdetails/index'),
    meta: { title: '订单详情', icon: 'form' },
    hidden: true
  }
  ]
},
{
  path: '/userApply',
  component: Layout,
  redirect: '/userApply/list',
  name: 'userApply',
  meta: { title: '用户管理', icon: 'el-icon-user' },
  children: [{
    path: '/userApply/list',
    name: 'List',
    component: () =>
      import('@/views/users/index'),
    meta: { title: '用户列表', icon: 'el-icon-user' }
  },
  {
    path: '/userApply/applydetail/:applyId',
    name: 'applydetail',
    component: () =>
      import('@/views/applydetail/index'),
    meta: { title: '用户详情', icon: 'form' }, hidden: true
  }
  ]
},
{
  path: '/note',
  component: Layout,
  redirect: '/note/list',
  name: 'note',
  meta: { title: '留言管理', icon: 'el-icon-notebook-2' },
  children: [{
    path: '/note/list',
    name: 'List',
    component: () =>
      import('@/views/note/index'),
    meta: { title: '留言列表', icon: 'el-icon-notebook-2' }
  },
  ]
},
{
  path: 'external-link',
  component: Layout,
  children: [{
    path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
    meta: { title: '外部链接', icon: 'link' }
  }]
},

// 404 page must be placed at the end !!!
{ path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
